Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
"in" operator chaining ( True in [True] in [True] OUTPUT: False )

I'm trying to figure out in what order this code runs:

print( True in [True] in [True] )
False

even though:

print( ( True in [True] ) in [True] )
True

and:

print( True in ( [True] in [True] ) )
TypeError

If the first code is neither of these two last ones, then what?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

in is comparing with chaining there so

True in [True] in [True]

is equivalent to (except middle [True] is evaluated once)

(True in [True]) and ([True] in [True])

which is

True and False

which is

False

This is all similar to

2 < 4 < 12

operation which is equivalent to (2 < 4) and (4 < 12).

over 4 years ago · Santiago Trujillo Denunciar

0

print( True in [True] in [True] )

This is actually interpreted as - True in [True] and [True] in [True] which gives you false because it becomes - True and False

print( ( True in [True] ) in [True] )

The ( True in [True] ) is checked first, so you get True in [True] which is True.

print( True in ( [True] in [True] ) )

The second part is checked, before the first because of parenthesis which changes the order, so it becomes - True in True. And True which is a boolean, is not a iterable, so you cannot use in, and then you get TypeError

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda